<template>
	<view class="claim-collage-more" v-if="isLoad">
		<view @tap="toJoin(index)" class="collage-item fill-base flex-center pd-lg" :class="[{'b-1px-t':index!=0}]"
			v-for="(item,index) in list.data" :key="index">
			<image class="avatar radius" :src="item.user_info.avatarUrl"></image>
			<view class="flex-1 flex-center ml-md">
				<view class="flex-1 mr-md flex-between">
					<view class="f-desc c-title max-150 ellipsis">{{item.user_info.nickName}}</view>
					<view>
						<view class="flex-between">
							<view></view>
							<view class="flex-y-center f-paragraph">差<view class="c-warning">{{item.surplus_num}}
								</view>人成团
							</view>
						</view>
						<view class="flex-y-center f-icontext c-caption">
							剩<min-countdown :type="5" :targetTime="item.end_time * 1000" color="#999"
								@callback="countEnd">
							</min-countdown>结束
						</view>
					</view>
				</view>
				<view class="common-btn flex-center f-paragraph c-base" :style="{background:primaryColor}">去参与
				</view>
			</view>
		</view>
		<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading" v-if="loading">
		</load-more>
		<abnor v-if="!loading&&list.data.length<=0&&list.current_page==1"></abnor>
		<view class="space-footer"></view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from "vuex"
	export default {
		components: {},
		data() {
			return {
				isLoad: false,
				options: {},
				param: {
					page: 1,
				},
				list: {
					data: []
				},
				loading: true,
				lockTap: false
			}
		},
		onLoad(options) {
			this.$util.showLoading()
			this.options = options
			this.initIndex()
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.list.current_page >= this.list.last_page || this.loading) return
			this.param.page = this.param.page + 1
			this.loading = true
			this.getList()
		},
		computed: mapState({
			primaryColor: state => state.config.configInfo.primaryColor,
			subColor: state => state.config.configInfo.subColor,
			userInfo: state => state.user.userInfo
		}),
		methods: {
			...mapActions(['']),
			async initIndex() {
				await this.getList()
				this.isLoad = true
				this.$util.hideAll()
			},
			initRefresh() {
				this.param.page = 1
				this.initIndex()
			},
			countEnd() {
				this.$util.log("倒计时完了")
				setTimeout(() => {
					this.initRefresh()
				}, 1000)
			},
			async getList() {
				let {
					list: oldList,
					param,
				} = this
				let {
					id
				} = this.options
				param.claim_id = id
				let newList = await this.$api.claim.claimCollageList(param);
				if (this.param.page == 1) {
					this.list = newList
				} else {
					newList.data = oldList.data.concat(newList.data)
					this.list = newList
				}
				this.loading = false
				this.$util.hideAll()
			},
			toJoin(index) {
				let {
					id: cid,
					claim_id,
					user_id,
					can_join,
				} = this.list.data[index]
				let {
					join_times
				} = this.$util.getPage(-1).detail.collage_data
				let {
					id: uid
				} = this.userInfo
				if (user_id == uid || !can_join) {
					this.$util.showToast({
						title: user_id == uid ? `不能参与自己发起的众筹哦` : `您已参与此众筹或已达到参与次数${join_times}`
					})
					return
				}
				let url = `/claim/pages/order?id=${claim_id}&cid=${cid}&type=2`
				this.$util.goUrl({
					url
				})
			},
		}
	}
</script>


<style lang="scss">
	.claim-collage-more {
		.collage-item {
			.avatar {
				width: 68rpx;
				height: 68rpx;
			}
		}
	}
</style>
